<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>视频投射</title>
  <script src="Cesium/Cesium.js"></script>
  <link href="Cesium/Widgets/widgets.css" rel="stylesheet" />
  <script src="plugin/cesium-VideoShed3D.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    html,
    body,
    #viewer-container {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }

    #btn {
      position: absolute;
      padding: 5px;
      top: 5px;
      left: 5px;
    }
  </style>
</head>

<body>
  <div id="viewer-container"></div>
  <div id="btn"><button onclick="create()">创建</button><button onclick="destroy()">删除</button></div>
  <script>
    // init
    function initPage() {
      // 切换自己的token
      Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYTQ2ZjdjNS1jM2E0LTQ1M2EtOWM0My1mODMzNzY3YjYzY2YiLCJpZCI6MjkzMjcsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1OTE5NDIzNjB9.RzKlVTVDTQ9r7cqCo-PDydgUh8Frgw0Erul_BVxiS9c';
      // 初始化
      let viewer = new Cesium.Viewer("viewer-container", {
        infoBox: false,
        shouldAnimate: true,
        vrButton: true,
        geocoder: false,
        homeButton: false,
        sceneModePicker: false,
        baseLayerPicker: true,
        navigationHelpButton: false,
        animation: false,
        timeline: false,
        fullscreenButton: false,
      });
      // LOAD 
      let tilesets = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
        url: 'http://earthsdk.com/v/last/Apps/assets/dayanta/tileset.json'
        // url: 'datas/SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json'
      }))
      viewer.flyTo(tilesets)
      // 参数
      let viewModel = { verticalAngle: 90, horizontalAngle: 120, distance: 10 };
      let videoShed3DArr = [];
      // 创建
      window.create = function () {
        let videoShed3D = new Cesium.VideoShed3D(viewer, {
          type: 'Video',
          url: "src/cs.mp4",
          alpha: 1,
          debugFrustum: true,
          horizontalAngle: Number(viewModel.horizontalAngle),
          verticalAngle: Number(viewModel.verticalAngle),
          distance: Number(viewModel.distance),
        });
        videoShed3DArr.push(videoShed3D)
      }
      // 销毁
      window.destroy = function () {
        videoShed3DArr.forEach(video => video.destroy())
      }
    }

    // load
    window.onload = function () {
      initPage()
    }
  </script>
</body>

</html>